package com.rabbiter.market.controller.user.sale;

import com.rabbiter.market.common.web.response.JsonResult;
import com.rabbiter.market.domain.sale.sale_records.SaleRecords;
import com.rabbiter.market.service.sale_management.sale_records.ISaleRecordsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * @author: longxianghang
 * @date: 2025/3/21 15:52
 * @description:
 */
@RestController
@RequestMapping("/sale")
public class SaleController {

    @Resource
    private ISaleRecordsService saleRecordsService;

    /**
     * 提交订单
     * @param saleRecords
     * @param request
     * @return
     */
    @PostMapping("/submit-order")
    public void saveSaleRecords(@RequestBody SaleRecords saleRecords, HttpServletRequest request, HttpServletResponse response) throws Exception {
        Date date = new Date();
        saleRecords.setSellTime(date);
        saleRecordsService.saveSaleRecords(saleRecords,(String) request.getHeader("token"), response);
    }

    /**
     * 根据cn查询订单信息
     * @param saleRecords
     * @return
     */
    @GetMapping("/getOrderByCn")
    public JsonResult<SaleRecords> getOrderByCn(SaleRecords saleRecords) {
        return JsonResult.success(saleRecordsService.getOrderByCn(saleRecords));
    }
}
